<?php
    require_once("dbconnect.php");
require_once("admin_functions.php");
require_once("classes/mail.php");

chk_session();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO nativeplace (nativeplace_id, nativeplace) VALUES (%s, %s)",
                       GetSQLValueString($_POST['cityid'], "int"),
                       GetSQLValueString($_POST['city'], "text"));

  mysql_select_db($database_sankalp, $sankalp);
  $Result1 = mysql_query($insertSQL, $sankalp) or die(mysql_error());
}

if ((isset($_POST['nativeplace_id'])) && ($_POST['nativeplace_id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM nativeplace WHERE nativeplace_id=%s",
                       GetSQLValueString($_POST['nativeplace_id'], "int"));


  $Result1 = mysql_query($deleteSQL) or die(mysql_error());
}


$query_city = "SELECT * FROM nativeplace";
$city = mysql_query($query_city) or die(mysql_error());
$row_city = mysql_fetch_assoc($city);
$totalRows_city = mysql_num_rows($city);
?>
<?php require_once('include/header1.php'); ?>
<?php require_once('include/sidebar.php'); ?>
<div id="admin_full_inner_body">

		<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#33CCFF">
  <tr>

    <td width="621" valign="top" ><p align="center" class="title"><br>
      Add City </p>
      <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
        <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="formfield">Add City : </td>
            <td><label for="textfield"></label>
            <input name="city" type="text" id="city" size="30">
            <input name="cityid" type="hidden" id="cityid">
            <span class="formfield">First name should be in Capital </span></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><label for="Submit"></label>
            <input type="submit" name="Submit" value="Add City" id="Submit"></td>
          </tr>
        </table>
          <input type="hidden" name="MM_insert" value="form1">
      </form>      <p align="center" class="title">
        <label for="select">Check City! : </label>
        <select name="select" id="select">
          <?php
do {
?>
          <option value="<?php echo $row_city['nativeplace_id']?>"><?php echo $row_city['nativeplace']?></option>
          <?php
} while ($row_city = mysql_fetch_assoc($city));
  $rows = mysql_num_rows($city);
  if($rows > 0) {
      mysql_data_seek($city, 0);
	  $row_city = mysql_fetch_assoc($city);
  }
?>
        </select>
      </p>
      <p align="center" class="title">How many cities Avilable </p>
      <p align="center" class="titlebar">Remove City </p>
      <p align="center">
        <label for="label"></label>
      </p>
      <form name="form2" method="post" action="">
        <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td>Select City for delete : </td>
            <td><label for="label"></label>
              <select name="city" id="label">
                <?php
do {
?>
                <option value="<?php echo $row_city['nativeplace_id']?>"<?php if (!(strcmp($row_city['nativeplace_id'], $row_city['nativeplace_id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_city['nativeplace']?></option>
<?php
} while ($row_city = mysql_fetch_assoc($city));
  $rows = mysql_num_rows($city);
  if($rows > 0) {
      mysql_data_seek($city, 0);
	  $row_city = mysql_fetch_assoc($city);
  }
?>
              </select>
            <input name="hiddenField" type="hidden" value="<?php echo $row_city['nativeplace_id']; ?>"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><label for="label2"></label>
            <input type="submit" name="Submit2" value="Delete City" id="label2"></td>
          </tr>
        </table>
      </form>
      <p align="center">&nbsp; </p><br />

</td>
  </tr>
</table>
</div>

    
		
<?php require_once('include/footer1.php'); ?>
